<?php

class User_AuthController extends Zend_Controller_Action
{

  public function init()
  {
    /* Initialize action controller here */
  }

  public function indexAction()
  {
    // action body
  }

  public function loginAction()
  {
    $this->view->form = $form = new Application_Form_Auth();

    $form->populate(array(
      'return_url' => $this->_getParam('return_url'),
    ));

    if (!$this->getRequest()->isPost()) {
      return;
    }

    if (!$form->isValid($this->getRequest()->getPost())) {
      return;
    }
    $values = $form->getValues();
    $user = new Application_Model_User();
    if ($user->authorize($values['email'], $values['password'])) {
//      $this->_redirect()
      if ($values['return_url']) {
        $this->_redirect($values['return_url']);
      } else {
        $this->redirect('/');
      }
    }
  }

  public function logoutAction()
  {
    Zend_Auth::getInstance()->clearIdentity();
    $this->_redirect('/');

  }


}